package xin.huangyan.accessibilityapp;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import xin.huangyan.accessibilityapp.internet.SocketManager;
import xin.huangyan.accessibilityapp.utils.HLog;

public class MainActivity extends AppCompatActivity {
    TextView txtTip;
    Button btnTest;
    boolean hasPermission = false;
    MyAccessibilityService accessibilityService;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txtTip = findViewById(R.id.txtTip);
        btnTest = findViewById(R.id.btnTest);
        btnTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "test btn click", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent();
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setClassName("xin.huangyan.cameraxapp", "xin.huangyan.cameraxapp.MainActivity");
                MainApplication.context.startActivity(intent);
            }
        });
    }

    public void onBtnPermission(View view) {
        HLog.i( "onBtnPermission");
        try {
            this.startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
        } catch (Exception e) {
            this.startActivity(new Intent(Settings.ACTION_SETTINGS));
            e.printStackTrace();
        }
    }

    public void onBtnSendMsg(View view) {
        HLog.i( "onBtnSendMsg");
        WeixinMsgManager.getInstance().sendMsg(null);
//        WeixinMsgManager.getInstance().inputMsg();

    }

    public void onBtnStartServer(View view) {
        SocketManager.getInstance().startService();
        ((Button)view).setText("服务已启动");
    }
    @Override
    protected void onResume() {
        super.onResume();
        accessibilityService = MyAccessibilityService.getService();
        if (accessibilityService != null) {
            hasPermission = true;
            txtTip.setText("辅助权限已获取");
        }else {
            hasPermission = false;
            txtTip.setText("权限未获取，请先获取权限");
        }
    }
}